import { UserProfilesAPI } from "@/request/api";
export default {
  namespaced: true,
  state: {
    userInfo: {
      //头像
      headImg: require("../../assets/img/service.848ec511.png"),
      //昵称
      nickName: "昵称",
      //积分
      coin: 0,
    },
    //购物车数量：
    cartTotal: 9,
  },
  mutations: {
    //修改用户信息
    changeUserInfo(state, payload) {
      // console.log("mutations", payload, payload.userInfo, payload.cartTotal);
      state.userInfo = payload.userInfo;
      state.cartTotal = payload.cartTotal;
    },

    initUserInfo(state) {

    },
  },
  actions: {
    async asycnChangeUserInfo({ commit }, payload) {
      //1. 请求用户信息
      let res = await UserProfilesAPI();
      // console.log("actions", res.data);
      //{userInfo:{},cartTotal:0}
      //2. 更新state数据 （mutations)
      commit("changeUserInfo", res.data);
    },
  },
};

